package com.yxinsur.imc.business.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yxinsur.imc.business.domain.ImcFundBrokerVariable;
import com.yxinsur.imc.business.domain.ImcFundOrderVariable;
import com.yxinsur.imc.business.mapper.ImcFundOrderVariableMapper;
import com.yxinsur.imc.business.service.IImcFundOrderVariableService;
import com.yxinsur.imc.business.vo.FundBrokerVariableVo;
import com.yxinsur.imc.business.vo.FundOrderVariableVo;
import com.yxinsur.imc.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 保单口径变量(对应下拉列应显示的内容)Service业务层处理
 *
 * @author imc
 * @date 2021-10-29
 */
@Service
public class ImcFundOrderVariableServiceImpl extends ServiceImpl<ImcFundOrderVariableMapper, ImcFundOrderVariable> implements IImcFundOrderVariableService {
    @Autowired
    private ImcFundOrderVariableMapper imcFundOrderVariableMapper;

    /**
     * 查询保单口径变量(对应下拉列应显示的内容)
     *
     * @param id 保单口径变量(对应下拉列应显示的内容)ID
     * @return 保单口径变量(对应下拉列应显示的内容)
     */
    @Override
    public ImcFundOrderVariable selectImcFundOrderVariableById(Long id) {
        return imcFundOrderVariableMapper.selectImcFundOrderVariableById(id);
    }

    /**
     * 查询保单口径变量(对应下拉列应显示的内容)列表
     *
     * @param imcFundOrderVariable 保单口径变量(对应下拉列应显示的内容)
     * @return 保单口径变量(对应下拉列应显示的内容)
     */
    @Override
    public List<ImcFundOrderVariable> selectImcFundOrderVariableList(ImcFundOrderVariable imcFundOrderVariable) {
        return imcFundOrderVariableMapper.selectImcFundOrderVariableList(imcFundOrderVariable);
    }

    /**
     * 新增保单口径变量(对应下拉列应显示的内容)
     *
     * @param imcFundOrderVariable 保单口径变量(对应下拉列应显示的内容)
     * @return 结果
     */
    @Override
    public int insertImcFundOrderVariable(ImcFundOrderVariable imcFundOrderVariable) {
        imcFundOrderVariable.setCreateTime(DateUtils.getNowDate());
        return imcFundOrderVariableMapper.insertImcFundOrderVariable(imcFundOrderVariable);
    }

    /**
     * 修改保单口径变量(对应下拉列应显示的内容)
     *
     * @param imcFundOrderVariable 保单口径变量(对应下拉列应显示的内容)
     * @return 结果
     */
    @Override
    public int updateImcFundOrderVariable(ImcFundOrderVariable imcFundOrderVariable) {
        imcFundOrderVariable.setUpdateTime(DateUtils.getNowDate());
        return imcFundOrderVariableMapper.updateImcFundOrderVariable(imcFundOrderVariable);
    }

    /**
     * 批量删除保单口径变量(对应下拉列应显示的内容)
     *
     * @param ids 需要删除的保单口径变量(对应下拉列应显示的内容)ID
     * @return 结果
     */
    @Override
    public int deleteImcFundOrderVariableByIds(String[] ids) {
        return imcFundOrderVariableMapper.deleteImcFundOrderVariableByIds(ids);
    }

    /**
     * 删除保单口径变量(对应下拉列应显示的内容)信息
     *
     * @param id 保单口径变量(对应下拉列应显示的内容)ID
     * @return 结果
     */
    @Override
    public int deleteImcFundOrderVariableById(String id) {
        return imcFundOrderVariableMapper.deleteImcFundOrderVariableById(id);
    }

    @Override
    public List<FundOrderVariableVo> listVariable() {
        List<ImcFundOrderVariable> variableList = this.imcFundOrderVariableMapper.listVariable();
        List<FundOrderVariableVo> variableVoList = CollUtil.newArrayList();
        variableList.forEach(item -> {
            FundOrderVariableVo variableVo = new FundOrderVariableVo();
            BeanUtil.copyProperties(item, variableVo);
            variableVo.setVariableItem(JSONUtil.parseArray(item.getVariableItem()));
            variableVoList.add(variableVo);
        });
        return variableVoList;
    }
}
